// 大数据第四题 
// author ：lbc
package homework1;

import java.io.IOException;

import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class catFileInfo {
    public static void main(String[] args) throws IOException, URISyntaxException {
        Configuration conf = new Configuration();
        String hdfsPath = "hdfs://localhost:9000";
        FileSystem hdfs = FileSystem.get(new URI(hdfsPath), conf);

        String pathHdfs = "hdfstest/touchfile.txt";
        catInfo(hdfs, pathHdfs);
        hdfs.close();

    }
    public static void catInfo(FileSystem fs, String pathHdfs) throws IOException{
        Path filepath = new Path(pathHdfs);
        SimpleDateFormat format = new SimpleDateFormat("HH: mm yyyy-MM-dd");
        FileStatus[] fileinfos = fs.listStatus(filepath);
        for(FileStatus fileinfo : fileinfos){
            System.out.println("Path: "+fileinfo.getPath().toString());
            System.out.println("Permission: "+ fileinfo.getPermission().toString());
            System.out.println("Size: "+ fileinfo.getLen());
            System.out.println("Time: "+ format.format(fileinfo.getModificationTime()));
        }
    }
}
